Ditto Query Language (DQL) offers a set of data types designed to accommodate any edge sync scenario.
REGISTER
, MAP
, and ATTACHMENT
type. By
default, fields in a DQL statement are assigned the REGISTER
type unless
otherwise specified by way of type definition.
Following are the key characteristics:
Type | REGISTER | MAP | ATTACHMENT | PN_COUNTER |
---|---|---|---|---|
CRDT type | Last-write-wins | Add-wins | Last-write-wins | Positive-negative |
Payload | Any | Object | Binary file | Double |
string
and boolean
, as well as a JSON blob, encapsulating multiple field‑value pairs
that function as a single object. The REGISTER
can only be set to a specific
field.
For example:
MAP
type supports inserting and tombstoning of fields using the functional
operators. Inserting a field is an implicit operation performed by assigning a
value to a field or a child of the field.
ATTACHMENT
data type, provide an ATTACHMENT
object:
INSERT
statement to insert a double value of 0.0
:
PN_INCREMENT
keyword followed by the value. To decrement a counter, use a
negative value.
SELECT
statement:
default()
functional operator.
REGISTER
→ NULL
AWMAP
→ Empty Map {}
ATTACHMENT
→ NOT SUPPORTEDPN_COUNTER
→ NOT SUPPORTEDREGISTER
is a data type in Ditto that stores a single scalar value and
uses last-write-wins merge strategy for handling conflicts.
Key characteristics of REGISTER:
DQL_STRICT_MODE=false
, if you want to force a JSON Object to use a
REGISTER data type instead of a MAP in DQL, it must be specified explicitly.
UNSET
statement at the top level. Because a register map is treated the same as a scalar value (such as string, int), you operate on the entire object as a whole, similar to a JSON blob.
SET
or UNSET
a nested key of a register using dot notation.
DQL_STRICT_MODE=false
, collection definitions for non-registers are no longer required.Read moreDQL_STRICT_MODE=true
, REGISTER
is the default type in DQL. That means
that you need to specify the type definition when overriding with type MAP
, PN_COUNTER
, or
ATTACHMENT
within your query.
DQL type definitions describe the schema of the documents within a specific
collection — defining the field types within the collection and specifying the
assigned data types for each field.
To explicitly declare the type definition as non-REGISTER
type, add a prefix
of COLLECTION
and the suffix of (field1 data_type, field2 data_type, ...)
to
list the fields within the collection and their associated data types:
COLLECTION
declares that the collection has a type definitionyour_collection_name
is the name of the collection from which you want to set a definition.(field1 data_type, field2 data_type, ...)
specifies the data type of each field such as REGISTER
, MAP
, or ATTACHMENT
MAP
(Add-Wins Map) contains fields with their own data type. Data types for these fields are defined using parentheses following the MAP
keyword. For example, MAP(sub1 data_type, sub2 data_type, ...)
:
MAP
with all other fields type REGISTER
:
ATTACHMENT
with all other fields type REGISTER
:
MAP
and a single ATTACHMENT
with all other fields type REGISTER
:
MAP
nested with another MAP
— with all other fields type REGISTER
:
REGISTER
: